"""
@File    :   route_depend.py
@Time    :   2024/03/28 23:35:28
@Author  :   Qrj
@Email   :   923207736@qq.com
@description   :   路由依赖(用于维持本业务的路由部分整洁)
"""

from typing import Annotated

from fastapi import Depends
from redis.asyncio import Redis
from sqlalchemy.ext.asyncio import AsyncSession

from src.business.admin.system.oauth2.auth.client_credentials.schemas.validate import (
    ClientCredentialsCreateDoubleTokenValidateSchema,
)
from src.business.admin.system.oauth2.auth.client_credentials.service import (
    ClientCredentialsService,
)
from src.business.admin.system.oauth2.token.schemas.out import (
    DoubleTokenCompleteOutSchema,
)
from src.dependencies.no_introduction import (
    depend_get_master_db_session,
    depend_get_token_redis_pool,
)


async def route_depend_client_credentials_create_double_token(
    create_schema: ClientCredentialsCreateDoubleTokenValidateSchema,
    db_session: Annotated[AsyncSession, Depends(depend_get_master_db_session)],
    token_redis_pool: Annotated[Redis, Depends(depend_get_token_redis_pool)],
) -> DoubleTokenCompleteOutSchema:
    """创建Oauth2客户端模式的双Token的路由依赖

    Args:
        create_schema: 创建所需参数
        db_session (Annotated[AsyncSession, Depends): 数据库连接池
        token_redis_pool (Annotated[Redis, Depends): token的redis连接池

    Returns:
        DoubleTokenCompleteOutSchema: 双Token信息
    """
    double_token = (
        await ClientCredentialsService.create_client_credentials_double_token(
            db_session, token_redis_pool, create_schema
        )
    )
    return double_token
